package com.epalmpay.controller.batchpay;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.epalmpay.bean.BatchPayAddInDTO;
import com.epalmpay.bean.BatchPayInfoBean;
import com.epalmpay.commom.BaseController;
import com.epalmpay.status.Rescode;
import com.epalmpay.dto.batchpay.BatchOrderInfoOutDTO;
import com.epalmpay.dto.batchpay.BatchPayInDTO;
import com.epalmpay.dto.batchpay.BatchPayInfoInDTO;
import com.epalmpay.dto.batchpay.BatchPayInfoListOutDTO;
import com.epalmpay.dto.batchpay.BatchPayInfoOutDTO;
import com.epalmpay.dto.batchpay.BatchPayListOutDTO;
import com.epalmpay.dto.system.BaseOutDTO;
import com.epalmpay.dto.system.PageDTO;
import com.epalmpay.entity.BatchPayInfo;
import com.epalmpay.entity.BatchPayRecords;
import com.epalmpay.entity.Page;
import com.epalmpay.service.withdraw.IBatchPayService;
import com.epalmpay.util.Tools;

@Controller
@RequestMapping(value="/merchant/batchpay")
public class BatchPayController extends BaseController {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	  @Autowired
	protected IBatchPayService batchPayService;
	  @RequestMapping(value = "/finishSubmitBatchPay", method = RequestMethod.POST)
	  @ResponseBody
	  public   BaseOutDTO finishSubmitBatchPay(BatchPayAddInDTO batchPayIn,HttpServletRequest request){
			BaseOutDTO baseOutDTO=new BaseOutDTO();
			try {

				 int reslut = batchPayService.doAddBatchPay(batchPayIn,request);					
				baseOutDTO.setErrorCode(Rescode.SUCCESS, "处理成功");
				
				return baseOutDTO;
			}
			 catch (Exception e) { 
				 baseOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, "处理出现异常");
				e.printStackTrace();
				return baseOutDTO;
			}
			
		   }
	  
	 
	  @RequestMapping(value = "/batchPayList", method = RequestMethod.POST)
	  @ResponseBody
	 public  BatchPayListOutDTO batchPayList(BatchPayInDTO batchPayIn,PageDTO pageDTO){
		BatchPayListOutDTO oilcardListOutDTO=new BatchPayListOutDTO();
		try {
			Page page=Tools.pageEmtity(pageDTO);
			
			 List<BatchPayRecords> batchPayRecodes = batchPayService.batchPayList(batchPayIn,page);			
			oilcardListOutDTO.setPage(page); 
			oilcardListOutDTO.setBatchPayList(batchPayRecodes);
			oilcardListOutDTO.setErrorCode(Rescode.SUCCESS, "处理成功");
			
			return oilcardListOutDTO;
		}
		 catch (Exception e) { 
			 oilcardListOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, "处理出现异常");
			e.printStackTrace();
		}
		return oilcardListOutDTO;
	  }
	  @RequestMapping(value = "/batchPayInfoList", method = RequestMethod.POST)
	  @ResponseBody
	public  BatchPayInfoListOutDTO batchPayInfoList(BatchPayInDTO batchPayIn,PageDTO pageDTO){
		  BatchPayInfoListOutDTO oilcardListOutDTO=new BatchPayInfoListOutDTO();
			try {
				Page page=Tools.pageEmtity(pageDTO);
				
				oilcardListOutDTO.setBatchPayRecords(batchPayService.findBatchPayRecord(batchPayIn.getBatchPayId()));
				 List<BatchPayInfoBean> batchPayInfos = batchPayService.batchPayInfoList(batchPayIn,page);			
				oilcardListOutDTO.setPage(page); 
				oilcardListOutDTO.setBatchPayInfoList(batchPayInfos);
				oilcardListOutDTO.setErrorCode(Rescode.SUCCESS, "处理成功");
				
				return oilcardListOutDTO;
			}
			 catch (Exception e) { 
				 oilcardListOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, "处理出现异常");
				e.printStackTrace();
			}
			return oilcardListOutDTO;
	  }
	  
	  
	  
	  @RequestMapping(value = "/batchRepayList", method = RequestMethod.POST)
	  @ResponseBody
	public  BatchPayInfoListOutDTO batchRepayList(BatchPayInDTO batchPayIn){
		  BatchPayInfoListOutDTO oilcardListOutDTO=new BatchPayInfoListOutDTO();
			try {
				
				oilcardListOutDTO.setBatchPayRecords(batchPayService.findBatchPayRecord(batchPayIn.getBatchPayId()));
				List<BatchPayInfoBean> batchPayInfos = batchPayService.batchRepayList(batchPayIn);			
				
				oilcardListOutDTO.setBatchPayInfoList(batchPayInfos);
				oilcardListOutDTO.setErrorCode(Rescode.SUCCESS, "处理成功");
				
				return oilcardListOutDTO;
			}
			 catch (Exception e) { 
				 oilcardListOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, "处理出现异常");
				e.printStackTrace();
			}
			return oilcardListOutDTO;
	  }
	  
	  @RequestMapping(value = "/batchOrderInfo", method = RequestMethod.POST)
	  @ResponseBody
	public  BaseOutDTO  batchOrderInfo(BatchPayInDTO batchPayIn){
		BatchOrderInfoOutDTO batchOrderInfoOutDTO=new BatchOrderInfoOutDTO();
			try {
				batchOrderInfoOutDTO= batchPayService.findBatchOrderInfo(batchPayIn.getBatchPayId());			
				
				batchOrderInfoOutDTO.setErrorCode(Rescode.SUCCESS, "处理成功");
				
				return batchOrderInfoOutDTO;
			}
			 catch (Exception e) { 
				 batchOrderInfoOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, "处理出现异常");
				e.printStackTrace();
			}
			return batchOrderInfoOutDTO;
	 }
	
	  /***
	   * 失败的记录进行编辑补代付
	   * @param batchPayIn
	   * @return
	   */	 
	  @RequestMapping(value = "/finishSinglePay", method = RequestMethod.POST)
	  @ResponseBody
	public  BaseOutDTO  finishSinglePay(BatchPayInfoInDTO batchPayIn){
		BaseOutDTO baseOutDTO=new BaseOutDTO();
			try {

				 int reslut = batchPayService.finishSinglePay(batchPayIn);			
				
				baseOutDTO.setErrorCode(Rescode.SUCCESS, "处理成功");
				
				return baseOutDTO;
			}
			 catch (Exception e) { 
				 baseOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, "处理出现异常");
				e.printStackTrace();
			}
			return baseOutDTO;
	  }
	  
	  @RequestMapping(value = "/finishBatchPay", method = RequestMethod.POST)
	  @ResponseBody
	public   BaseOutDTO finishBatchPay(BatchPayInDTO batchPayIn){
		BaseOutDTO baseOutDTO=new BaseOutDTO();
		try {

			baseOutDTO = batchPayService.finishBatchPay(batchPayIn);					
			
			
			return baseOutDTO;
		}
		 catch (Exception e) { 
			 baseOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, "处理出现异常");
			e.printStackTrace();
		}
		return baseOutDTO;
	   }
	  
	  @RequestMapping(value = "/finishUpdatePayInfo", method = RequestMethod.POST)
	  @ResponseBody
	public   BaseOutDTO finishUpdatePayInfo(BatchPayInfoInDTO batchPayIn){
		BaseOutDTO baseOutDTO=new BaseOutDTO();
		try {

			baseOutDTO = batchPayService.finishUpdatePayInfo(batchPayIn);					
			
			
			return baseOutDTO;
		}
		 catch (Exception e) { 
			 baseOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, "处理出现异常");
			e.printStackTrace();
		}
		return baseOutDTO;
	   }
	  
	  
	  @RequestMapping(value = "/singlePayInfo", method = RequestMethod.POST)
	  @ResponseBody
	public   BatchPayInfoOutDTO singlePayInfo(BatchPayInDTO batchPayIn){
		  BatchPayInfoOutDTO baseOutDTO=new BatchPayInfoOutDTO();
		try {

			 BatchPayInfo batchPayInfo= batchPayService.findSinglePayInfo(batchPayIn.getBatchPayInfoId());					
			 baseOutDTO.setBatchPayInfo(batchPayInfo);
			 baseOutDTO.setErrorCode(Rescode.SUCCESS, "处理成功");
			return baseOutDTO;
		}
		 catch (Exception e) { 
			 baseOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, "处理出现异常");
			e.printStackTrace();
		}
		return baseOutDTO;
	   }
	  

	  @RequestMapping(value = "/synBatchRecord", method = RequestMethod.POST)
	  @ResponseBody
	public   BaseOutDTO synBatchRecord(BatchPayInDTO batchPayIn){
		BaseOutDTO baseOutDTO=new BaseOutDTO();
		try {

			baseOutDTO = batchPayService.finishsynBatchRecord(batchPayIn);					
			
			
			return baseOutDTO;
		}
		 catch (Exception e) { 
			 baseOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, "处理出现异常");
			e.printStackTrace();
		}
		return baseOutDTO;
	   }
	  
	  @RequestMapping(value = "/finishSycPayResult", method = RequestMethod.POST)
	  @ResponseBody
	public   BaseOutDTO finishSycPayResult(BatchPayInDTO batchPayIn){
		BaseOutDTO baseOutDTO=new BaseOutDTO();
		try {

			baseOutDTO = batchPayService.finishSycPayResult(batchPayIn.getBatchPayInfoId());					
			
			
			return baseOutDTO;
		}
		 catch (Exception e) { 
			 baseOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, "处理出现异常");
			e.printStackTrace();
		}
		return baseOutDTO;
	   }
	  
	 

}
